/**
 * IBatisManager.java : [com.raccoon.ibatis.config] Created on 2009. 4. 13.
 *
 * Copyright (c) 2009 Raccoon Project Team.
 * Seoul, Korea
 * All rights reserved.
 *
 */
package com.raccoon.ibatis.config;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.raccoon.ibatis.bean.MemberExBean;

/**
 * @author KimJungSu
 * @version
 *
 */
public class IBatisManager {

	private static SqlMapClient sqlMapper;

	public IBatisManager() {
		try {
			Reader reader = Resources.getResourceAsReader("com/raccoon/ibatis/config/sqlMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			// Fail fast.
			throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
		}
	}

	public static Map selectMemberAll(HashMap map) throws SQLException {
		return sqlMapper.queryForMap("selectMember_dynamic_1", map, "");
	}

	public static MemberExBean selectMemberWithUserKey(int key) throws SQLException {
		return (MemberExBean) sqlMapper.queryForObject("selectMember_userKey", key);
	}

	public static List selectMemberWithLike(String str) throws SQLException {
		return sqlMapper.queryForList("selectMember_like", str);
	}
}
